using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.MediaPlayer.Interop;
using System.Diagnostics;


namespace VTour2
{
    public partial class Form1 : Form
    {
        //private int x = 307;
        private int x = 0;
        private int y = 0;
        private int totalX = 640;
        private int startX = 0;
        private int startY = 0;
        private bool zoom = false;
        private bool isDragging = false;
        private Image map = new Bitmap("/My Documents/Vtour2/GasTownMap.png");
        FormVideo formVideo = new FormVideo();



        public Form1()
        {
            InitializeComponent();
            Map.Image = map;
            x = this.pictureBox1.Location.X;
            y = this.pictureBox1.Location.Y-2;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (totalX < 460)
                trip2();
            else
                trip1();

            
            if (totalX < 320 && totalX > 317)
            {
                this.Map.Image = new Bitmap("/My Documents/Vtour2/BottomLeft.JPG");
                x = 320;
                y = 0;
            }

            if (totalX < 100)
            {
                timer1.Enabled = false;
                MessageBox.Show("Thank you for visiting Gas Town", "Bye", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
            }

            this.pictureBox1.Location = new Point(x, y);

            if (totalX == 211)
            {
                timer1.Enabled = false;
                DialogResult result = MessageBox.Show("Would you like more info about this place?", "This is the Gas Town Clock", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                if (result == DialogResult.Yes)
                {
                    
                    Process process = new Process();
                    process.StartInfo.FileName = "/My Documents/Vtour2/GasTown.wmv";
                    process.StartInfo.Verb = "Open";
                    process.StartInfo.UseShellExecute = true;
                    process.Start();
                }
                else
                    timer1.Enabled = true;
            }
        }

        private void trip1()
        {
            x = x - 3;
            totalX = totalX - 3;
            y = y - 1;
        }

        private void trip2()
        {
            x = x - 2;
            totalX = totalX - 2;
            y = y + 1;
        }

        private void Map_DoubleClick(object sender, EventArgs e)
        {

        }

        private void Map_MouseDown(object sender, MouseEventArgs e)
        {
            isDragging = true;
            menu.Visible = false;
            timer2.Enabled = true;
            timer3.Enabled = true;
            startX = e.X;
            startY = e.Y;
        }

        private void Map_MouseUp(object sender, MouseEventArgs e)
        {
            isDragging = false;
            timer2.Enabled = false;
            timer3.Enabled = false;
        }

        private void Map_MouseMove(object sender, MouseEventArgs e)
        {
            if (isDragging)
            {
                if (!(e.X + Map.Left - startX > 0) && !(e.X + Map.Right - startX < 320))
                    Map.Left = e.X + Map.Left - startX;
                if (!(e.Y + Map.Top - startY > 0) && !(e.Y + Map.Bottom - startY < 240))
                    Map.Top = e.Y + Map.Top - startY;
            }           
        }

        private void zoomButton_Click(object sender, EventArgs e)
        {
            int tempX = Map.Location.X;
            int tempY = Map.Location.Y;

            if (!zoom)
            {
                Map.Size = new Size(Map.Size.Width * 2, Map.Size.Height * 2);
                zoom = true;
                Map.Location = new Point(tempX * 2 - 160, tempY * 2 - 120);
            }
            else
            {
                tempX = tempX / 2 + 80;
                tempY = tempY / 2 + 60;

                Map.Size = new Size(Map.Size.Width / 2, Map.Size.Height / 2);
                zoom = false;

                if (tempX > 0)
                    tempX = 0;
                if (tempX < 320 - Map.Width)
                    tempX = 320 - Map.Width;
                if (tempY > 0)
                    tempY = 0;
                if (tempY < 240 - Map.Height)
                    tempY = 240 - Map.Height;
                Map.Location = new Point(tempX, tempY);
            }
            menu.Visible = false;
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            menu.Visible = true;
            timer2.Enabled = false;
        }

        private void powerButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void timer3_Tick(object sender, EventArgs e)
        {
            if (zoom)
            {
                if (startX > 218 * 2 && startX < 236 * 2 && startY > 228 * 2 && startY < 260 * 2)
                {                   
                    formVideo.Visible = true;
                    formVideo.play();
                    timer2.Enabled = false;
                }
            }

            else
            {
                if (startX > 208 && startX < 246 && startY > 208 && startY < 260)
                {
                    formVideo.Visible = true;
                    formVideo.play();
                    timer2.Enabled = false;
                }
            }
            timer3.Enabled = false;
        }

    }
}